package com.stalltea.jdk8.lambda.optional;

import java.util.Optional;

/**
 * @author yivlchangfa
 * @since 2021/9/16 13:25
 */
public class OptionalStudy {

    public static void main(String[] args) {
        Person person = new Person();
        Optional<Person> optPerson = Optional.of(person);
        System.out.println(optPerson
                .flatMap(Person::getCar)
                .flatMap(Car::getInsurance)
                .map(Insurance::getName).orElse("1111"));

//        Optional<Car> optCar = Optional.of(new Car());
//        Optional<String> s = optCar.flatMap(Car::getInsurance)
//                .map(Insurance::getBrand)
//                .map(Brand::getName);
//        System.out.println(s.get());
    }

}
